package com.huihui.springbootshiro.service.impl;

import com.huihui.springbootshiro.dao.UserDao;
import com.huihui.springbootshiro.entity.Perms;
import com.huihui.springbootshiro.entity.User;
import com.huihui.springbootshiro.service.UserService;
import com.huihui.springbootshiro.utils.SaltUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 项目名称: springboot-shiro
 * @ClassName UserServiceImpl
 * @Description
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2021/7/6 15:32
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public void register(User user) {
        //处理业务调用dao
        String salt = SaltUtils.getSalt();
        user.setSalt(salt);
        Md5Hash md5Hash = new Md5Hash(user.getPassword(), salt, 1024);
        user.setPassword(md5Hash.toHex());
        userDao.save(user);
    }

    @Override
    public User findUserByName(String username) {
        return userDao.findUserByName(username);
    }

    @Override
    public User findRolesByUserName(String username) {
        return userDao.findRolesByUserName(username);
    }

    @Override
    public List<Perms> findPermsByRoleId(String id) {
        return userDao.findPermsByRoleId(id);
    }
}
